package com.travel.api.interceptor

import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import org.springframework.web.servlet.config.annotation.CorsRegistry



@Configuration
class MvcConfigurer : WebMvcConfigurer {

    /**
     * 配置跨域请求
     * @param registry
     */
    override fun addCorsMappings(registry: CorsRegistry) {
        registry!!.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                .maxAge(3600)
                .allowCredentials(true)
    }


    override fun addInterceptors(registry: InterceptorRegistry) {

        registry.addInterceptor(SystemInterceptor())
                .addPathPatterns("/**")

        registry.addInterceptor(UserInterceptor())
                .addPathPatterns("/admin/**")
                .addPathPatterns("/user/**")
    }

}
